﻿
Partial Class DetailKhachSan
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Session("IDCity") IsNot Nothing AndAlso Not Session("IDCity").Equals("") AndAlso Request.QueryString("IDKS") IsNot Nothing Then
            Dim arrivalDate As Date = Nothing
            Dim departureDate As Date = Session("DepartureDate")
            arrivalDate = Now.Date
            If Session("ArrivalDate") IsNot Nothing AndAlso Not Session("ArrivalDate").Equals("") Then
                arrivalDate = Session("ArrivalDate")
            End If
            For i As Integer = 0 To 60
                Dim _mDate As Date = DateAdd(DateInterval.Day, +i, arrivalDate)
                Dim valueDay As String = _mDate 'String.Format("{0}/{1}/{2}", _mDate.Day, _mDate.Month, _mDate.Year)
                Dim showDate As String = String.Format("{0}/{1}/{2}", _mDate.Day, _mDate.Month, _mDate.Year)
                Dim textDay As String = String.Format("{0} {1}", Util.GetThuTrongTuan(CInt(_mDate.DayOfWeek), "Chủ Nhật"), showDate)
                Dim item As New ListItem(textDay, valueDay)
                txtCheckInDate.Items.Add(item)
            Next
            If Not IsPostBack Then
                'DetailKhachSan.aspx?IDKS={0}
                Dim khachSan As KhachSan = Nothing
                If Request.QueryString("IDKS") IsNot Nothing Then
                    Dim idKS As New Guid(Request.QueryString("IDKS"))
                    khachSan = KhachSanServer.GetKhachSanByIDKhachSan(idKS)
                    'Dim strCity As String = KhachSanServer.GetCityNameByIDCity(khachSan.CITY_ID)
                    divNameHotel.InnerHtml = khachSan.NAME
                    lnkQuayLai.Text = "Khách Sạn tại " + Session("NameCity")
                    Dim strURLQuayLai As String = String.Format("~/SearchKhachSan.aspx?ArrivalDate={0}&DepartureDate={1}&CityID={2}&Guests={3}&Rooms={4}", Session("ArrivalDate"), Session("DepartureDate"), Session("IDCity"), Session("Guests"), Session("Rooms"))
                    lnkQuayLai.PostBackUrl = strURLQuayLai
                    ''            
                    divKhuyenMaiVaLoaiPhong.InnerHtml = ""
                    Dim listKhuyenMai As List(Of KhuyenMaiTheoHotel) = KhuyenMaiTheoHotelServer.GetListKhuyenMaiByIDHotel(idKS)
                    For iKM As Integer = 0 To listKhuyenMai.Count - 1
                        divKhuyenMaiVaLoaiPhong.InnerHtml = divKhuyenMaiVaLoaiPhong.InnerHtml + SetListKhuyenMai(listKhuyenMai(iKM))
                    Next
                    Dim listLoaiPhong As List(Of KhachSan) = KhachSanServer.GetLoaiHotelByIdHotel(idKS)
                    For iLP As Integer = 0 To listLoaiPhong.Count - 1
                        divKhuyenMaiVaLoaiPhong.InnerHtml = divKhuyenMaiVaLoaiPhong.InnerHtml + SetListLoaiPhong(listLoaiPhong(iLP))
                    Next               
                    lnkDatPhong.PostBackUrl = String.Format("~/DetailKhachSanPut.aspx?IDKS={0}&IDLP={1}", Request.QueryString("IDKS"), listLoaiPhong(0).IDLOAIPHONG)

                End If
            End If
        Else
            Response.Redirect("~/index.aspx")
        End If
    End Sub

    Private Function SetListKhuyenMai(ByVal khuyenMai As KhuyenMaiTheoHotel) As String
        Dim strKhuyenMaiVaLoaiPhong As String = "<div class='' style='border-bottom: 1px solid #888; padding: 10px 0;'>"
        strKhuyenMaiVaLoaiPhong &= "<input class='hdItemId' type='hidden' value='e3260f71-e32d-4713-880f-28d11043edb8'>"
        strKhuyenMaiVaLoaiPhong &= "<div style=''>"
        Dim strURLKhuyenMai As String = String.Format("DetailKhachSanSale.aspx?IDKS={0}", Request.QueryString("IDKS"))
        strKhuyenMaiVaLoaiPhong &= "<a class='ui-link' href='" + strURLKhuyenMai + "' data-ajax='false'>" + khuyenMai.NAME_KM + "</a>"
        strKhuyenMaiVaLoaiPhong &= "</div>"
        If khuyenMai.HIENTHIGIA = True AndAlso khuyenMai.GIA_RE > 0 Then
            strKhuyenMaiVaLoaiPhong &= "<div style='float: left;'><div id='ctl00_ContentPlaceHolder1_repRates_ctl01_divShowPrice'>"
            strKhuyenMaiVaLoaiPhong &= "<div class='rate' style='margin-top: 10px;'>" + Format(khuyenMai.GIA_RE, "#,###") + "</div>"
            strKhuyenMaiVaLoaiPhong &= "<div style='font-weight: normal; font-size: .8em; color: #999;'> VND/đêm</div></div></div>"
        Else
            strKhuyenMaiVaLoaiPhong &= "<div style='float: left;'>"
            strKhuyenMaiVaLoaiPhong &= "<div id='ctl00_ContentPlaceHolder1_repRates_ctl01_divHidePrice' class='top-15 bottom-15'>"
            Dim strURLLayGia As String = String.Format("GetPrice.aspx?IDKS={0}&IDKM={1}", Request.QueryString("IDKS"), khuyenMai.IDKHUYENMAI)
            strKhuyenMaiVaLoaiPhong &= "<a class='ui-link' style='text-decoration:none;' href='" + strURLLayGia + "' data-ajax='false'>"
            strKhuyenMaiVaLoaiPhong &= "<label style=""cursor:pointer;"" class='ui-corner-all label_clicklaygia' >Click lấy giá</label>"
            strKhuyenMaiVaLoaiPhong &= "</a>"
            strKhuyenMaiVaLoaiPhong &= "</div>"
            strKhuyenMaiVaLoaiPhong &= "</div>"
        End If
        strKhuyenMaiVaLoaiPhong &= "<div style='float: right; text-align: center; font-size: .8em;'>"
        Dim strURL As String = String.Format("DetailKhachSanPut.aspx?IDKS={0}&IDKM={1}", Request.QueryString("IDKS"), khuyenMai.IDKHUYENMAI)
        strKhuyenMaiVaLoaiPhong &= "<a href='" + strURL + "' data-role=""button"" data-inline=""true"" data-theme=""b"" data-ajax=""false"">Đặt Khuyến Mãi"
        strKhuyenMaiVaLoaiPhong &= "</a>"
        strKhuyenMaiVaLoaiPhong &= "<br>"
        strKhuyenMaiVaLoaiPhong &= "<a class='ui-link' href='tel:08 38302686' style='font-weight: normal; font-size: .8em;'>08 38302686</a>"
        strKhuyenMaiVaLoaiPhong &= "</div>"
        strKhuyenMaiVaLoaiPhong &= "<div style='clear: both;'> </div>"
        strKhuyenMaiVaLoaiPhong &= "</div>"
        'divKhuyenMaiVaLoaiPhong.InnerHtml = divKhuyenMaiVaLoaiPhong.InnerHtml + strKhuyenMaiVaLoaiPhong
        Return strKhuyenMaiVaLoaiPhong
    End Function

    Private Function SetListLoaiPhong(ByVal khachSan As KhachSan) As String
        ' Dim loaiPhongTT As KhachSan = KhachSanServer.GetLoaiHotelByIdLoaiPhong(khachSan.ID, khachSan.IDLOAIPHONG)
        Dim result As String = "<div class='' style='border-bottom: 1px solid #888; padding: 10px 0;'>"
        result &= "<input class='hdItemId' type='hidden' value='e3260f71-e32d-4713-880f-28d11043edb8'>"
        result &= "<div style=''>"
        result &= "<b>" + khachSan.NAMELOAIPHONG + "</b>"
        result &= "</div>"
        If khachSan.HIENTHIGIA = True AndAlso khachSan.GIA > 0 Then
            'result &= "<div style='float: left;'><div id='ctl00_ContentPlaceHolder1_repRates_ctl01_divShowPrice'>"
            'result &= "<div class='rate' style='margin-top: 10px;'>" + Format(khachSan.GIA, "#,###") + "</div>"
            'result &= "<div style='font-weight: normal; font-size: .8em; color: #999;'> VND/đêm</div></div></div>"
            ''
            Dim arrivalDate As Date = Nothing
            arrivalDate = Now.Date
            If Session("ArrivalDate") IsNot Nothing AndAlso Not Session("ArrivalDate").Equals("") Then
                arrivalDate = Session("ArrivalDate")
            End If
            Dim valueDay As String = String.Format("{0}/{1}/{2}", arrivalDate.Day, arrivalDate.Month, arrivalDate.Year)

            Dim strViewPrice As String = "<div style='padding:7px 15px 0;'>"
            strViewPrice &= " <table class='detailed-rates' cellspacing='1' cellpadding='0'>"
            strViewPrice &= " <tbody><tr><th class='stay-date'> Ngày lưu trú </th>"
            strViewPrice &= " <th class='daily-rate'> Giá phòng mỗi ngày </th><th class='daily-rate'> Thành viên </th></tr>"
            strViewPrice &= " <tr><td class='stay-date'>" + valueDay + "</td><td class='daily-rate'>" + Format(khachSan.GIA, "#,###") + "</td>"
            strViewPrice &= " <td class='discount tdDiscountPercentageForMember'></tr>"
            strViewPrice &= " </tbody></table></div>"
            ''
            result &= "<div style='float: left;'>"
            result &= "<div id='' class='bottom-10'>"
            Dim strOnclick As String = String.Format("onclick=""HideAndShow(this, '{0}', '{1}', 0);""", Request.QueryString("IDKS"), khachSan.IDLOAIPHONG)
            result &= "<a " + strOnclick + " data-ajax=""false"" class='lnkRoomTypePrice ui-link' id_hide='detailed_rates_" + khachSan.IDLOAIPHONG.ToString().Replace("-", "") + "' style='font-weight:normal; font-size:0.9em;' isfirstclick='true' show='0' hidetext='» Ẩn giá phòng' showtext='» Xem giá phòng' href='javascript:void(0);'>» Xem giá phòng</a>"

            result &= "<div id='detailed_rates_" + khachSan.IDLOAIPHONG.ToString().Replace("-", "") + "' class='hide' style='display: none; padding-bottom:5px;'>" + strViewPrice + "</div>"
            result &= "</div>"

        Else
            result &= "<div style='float: left;'>"
            result &= "<div id='' class='top-15 bottom-15'>"
            Dim strURLLayGia As String = String.Format("GetPrice.aspx?IDKS={0}&IDLP={1}", Request.QueryString("IDKS"), khachSan.IDLOAIPHONG)
            result &= "<a class='ui-link' style='text-decoration:none;' href='" + strURLLayGia + "' data-ajax='false'>"
            result &= "<label style=""cursor:pointer;"" class='ui-corner-all label_clicklaygia' " + strURLLayGia + "'>Click lấy giá</label>"
            result &= "</a>"
            result &= "</div>"
            result &= ""
        End If

        result &= "<div id='ctl00_ContentPlaceHolder1_repRates_ctl03_divRoomTypeInfo'>"
        Dim strOnclickTT As String = String.Format("onclick=""HideAndShow(this, '{0}', '{1}', 1);""", Request.QueryString("IDKS"), khachSan.IDLOAIPHONG)
        result &= "<a " + strOnclickTT + " data-ajax=""false"" class='lnkRoomTypeInfo ui-link' style='font-weight:normal; font-size:0.9em' isfirstclick='true' show='0' hidetext='» Ẩn thông tin loại phòng' showtext='» Xem thông tin loại phòng' id_hide='detailed_info_cancel" + khachSan.IDLOAIPHONG.ToString().Replace("-", "") + "' href='javascript:void(0);'>» Xem thông tin loại phòng</a>"
        ''

        Dim strViewTTLP As String = ""
        'strViewTTLP &= "<br><div class='a12'>Thông tin phòng<b> &nbsp;" + khachSan.NAMELOAIPHONG + "</b></div>"
        ''strViewTTLP &= " <img style='margin: 5px 0;max-width:400px;width:100%;' alt='Signature Superior' src='http://du-lich.Khachsan24gio.com/f/m/1310/17/khach-san-palace-sai-gon-8.jpg?w=400&c=1'>"
        'strViewTTLP &= " <div class='content'><div class='qui-dinh-2'>"
        'If khachSan.DESCRIPTIONLOAIPHONG.Equals("") Then
        '    strViewTTLP &= " <p>Phòng có diện tích khoảng " + khachSan.DIEN_TICH + ". " + khachSan.DESCRIPTIONLOAIPHONG + "</p></div><div class='qui-dinh-2'>"
        '    'strViewTTLP &= " <span>Phòng có bao gồm ăn sáng<br></span><span></span>"
        '    strViewTTLP &= " <span>Phòng dành cho " + khachSan.SO_NGUOI.ToString() + " người<br></span>"
        '    If khachSan.SO_GIUONG_DOI > 0 Then
        '        strViewTTLP &= " <span>Phòng có " + khachSan.SO_GIUONG_DOI.ToString() + " giường đôi<br></span>"
        '    End If
        '    If khachSan.SO_GIUONG_DON > 0 Then
        '        strViewTTLP &= " <span>Phòng có " + khachSan.SO_GIUONG_DON.ToString() + " giường đơn<br></span>"
        '    End If
        '    strViewTTLP &= " <span></span><span></span>"
        'Else
        '    strViewTTLP &= " <p>" + khachSan.DESCRIPTIONLOAIPHONG + "</p>"
        'End If
        'strViewTTLP &= " </div><div class='qui-dinh-2'><br>"
        'strViewTTLP &= " <div class='sub-sub-title'><b> Tiện nghi - Dịch vụ trong phòng</b></div>"
        'strViewTTLP &= " <table id='repRoomTypeInfos_ctl02_dlRoomFacilities' cellspacing='0' cellpadding='5' border='0' style='border-collapse:collapse;'><tbody>"
        'Dim arrDichVuTN As ArrayList = KhachSanServer.GetDichVuTienNghiByIDLoaiPhong(khachSan.ID, khachSan.IDLOAIPHONG)
        'For i As Integer = 0 To arrDichVuTN.Count - 1 Step 2
        '    strViewTTLP &= " <tr> "
        '    strViewTTLP &= " <tr><td><div class='bullet'> " + arrDichVuTN(i) + "</div></td>"
        '    strViewTTLP &= "<td><div class='bullet'> " + arrDichVuTN(i + 1) + "</div></td>"
        '    strViewTTLP &= "</tr>"
        'Next
        'strViewTTLP &= " </tbody></table></div>"
        'strViewTTLP &= "</div>"
        ''
        result &= "<div class='RoomTypeInfos top-10' id='detailed_info_cancel" + khachSan.IDLOAIPHONG.ToString().Replace("-", "") + "' style='display: none;'>"

        result &= "</div></div></div>"

        result &= "<div style='float: right; text-align: center; font-size: .8em;'>"
        Dim strURL As String = String.Format("DetailKhachSanPut.aspx?IDKS={0}&IDLP={1}", Request.QueryString("IDKS"), khachSan.IDLOAIPHONG)
        result &= "<a href=" + strURL + " data-role=""button"" data-inline=""true"" data-theme=""b"" data-ajax=""false"">Đặt Phòng"
        result &= "</a>"
        result &= "<br>"
        result &= "<a class='ui-link' href='tel:08 38302686' style='font-weight: normal; font-size: .8em;'>08 38302686</a>"
        result &= "</div>"
        result &= "<div style='clear: both;'> </div>"
        result &= "</div>"
        Return result
    End Function


    Protected Sub lnkXemGiaPhong_Click(sender As Object, e As EventArgs) Handles lnkXemGiaPhong.Click
        Try
            Dim arriDate As Date = CDate(txtCheckInDate.Value)
            Session("ArrivalDate") = arriDate.Year.ToString() + "/" + arriDate.Month.ToString() + "/" + arriDate.Day.ToString()
            Dim _Date As Date = DateAdd(DateInterval.Day, +1, Session("ArrivalDate"))
             Session("DepartureDate") = _Date.Year.ToString() + "/" + _Date.Month.ToString() + "/" + _Date.Day.ToString()
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub
End Class
